home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
bit
/
src
/
fio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
31KB
|
1,231 lines
/*
* $Id: fio.c,v 0.91 1994/02/20 00:53:00 zhao Pre-Release $
*
*. This file is part of BIT shareware package. After the two weeks of
* free evaluation period, you are encouraged (required) to register
* your copy for a small registration fee, which is $35 for personal use
* and $50 for commercial, government and institutional use.
*
* Copyright(c) 1993, 1994 by T.C. Zhao.
* All rights reserved.
*
* Permission to use, copy, and distribute this software in its entirety
* for non-commercial purposes is hereby granted, provided that the
* above shareware and copyright notices and this permission notice
* appear in all copies and their documentation.
*
* This software may be modified for your own use, but modified versions
* may not be distributed without prior consent of the author.
*
* This software is provided "as is" without expressed or implied
* warranty of any kind.
*
*.
* GUI part of the file stuff: A file selector. Custom file loader dumper.
*
*/
#if !defined(lint) && defined(F_ID)
char *id_fio = "$Id: fio.c,v 0.91 1994/02/20 00:53:00 zhao Pre-Release $";
#endif
#include "bit.h"
#include "extern.h"
#include "dmalloc.h"
/********************* Limits and defines ********************/
#define MAXPATL 40 /* max pattern length */
#define MAXCFL (MAXDLEN + MAXFLEN) /* dir + fname length */
/***************** Local variables **************************/
static char fname[MAXFLEN + 3]; /* current selected finename */
static int rescan; /* if update dir cache */
static char cmfn[MAXCFL + 2]; /* complet filename */
static char *dirname, *pattern; /* points to different area */
static FL_OBJECT *browser; /* alias to the acutal browser */
/*************** Local functions ***************************/
static void create_the_forms(void);
/************* some utility functions ************/
/*****************************************************************
* Expand directory name and terminate it properly, i.e, ends in /
*****************************************************************/
static char *
fix_dir(char dir[])
{
int k;
if (fix_dirname(dir) != dir)
{
Bark("FioFixDir", "Something is wrong");
}
k = strlen(dir);
return (dir[k - 1] != '/') ? strcat(dir, "/") : dir;
}
/**************************************************************
* change/append an appropriate extension to the image filename
***************************************************************/
static void
change_extension(char name[], const char *new)
{
register char *p;
if (auto_ext) /* do extension only if requested */
{
p = name + strlen(name) - 1;
/* remove the extension */
while (p > name && *p != '.')
p--;
if (p <= name)
strcat(name, ".");
else
*++p = '\0';
/* add the extension */
strcat(name, new);
}
}
/**************************************************************
* select files according to selection pattern
*************************************************************/
#include <sys/stat.h>
static struct stat ffstat;
#if 0
static int precheck = 1; /* controls load_file routine */
#endif
static int mload; /* indicate if load_file */
/***************************************************************
* show selected file names in the browser. Routine itself
* is blind in the sense that it doesn't care where is called
* and for what. It only manipulates object BR
***************************************************************/
static int
load_browser(FL_OBJECT * br, const char *dir,
const char *pat, const char *fn)
{
Dirlist *dirlist;
int i, fnumb;
show_busy("ReadingDir ...");
#ifdef MDEBUG
M_debug("LoadBrowser", "dir=%s pat=%s file=%s", dir, pat, fn);
#endif
if (!(dirlist = get_dir_list(dir, pat, &fnumb, rescan)))
{
Bark("LoadDir", dir);
end_busy();
return -1;
}
fl_freeze_form(br->form);
fl_clear_browser(br);
for (i = 0; dirlist[i].name; i++)
{
if (dirlist[i].type == FT_DIR)
{
sprintf(cmfn, "D %s", dirlist[i].name);
fl_add_browser_line(br, cmfn);
}
else if (dirlist[i].type == FT_FILE)
{
fl_add_browser_line(br, dirlist[i].name);
if (fn && Streq(dirlist[i].name, fn))
fl_select_browser_line(br, i + 1);
}
}
fl_unfreeze_form(br->form);
end_busy();
return fnumb;
}
/***************************************************************
*
* A File Seclector.
*
**************************************************************/
#define FSELECT_CB 3
static FL_FORM *load1;
static FL_OBJECT *l1pat, *l1dir, *l1browser, *l1title;
static FL_OBJECT *l1ok, *l1cancel;
static char l1dirname[MAXDLEN + 1];
static char l1pattern[MAXPATL + 1];
static char combined[MAXDLEN + MAXFLEN + 1];
/***********************************************************
* Global entry point to get a filename
***********************************************************/
const char *
getfilename(const char *prom, const char *dir,
const char *pat, const char *fn, int block)
{
int bd = 1;
FL_OBJECT *ret;
short val;
char *pf = 0;
const char *fnonly;
create_the_forms();
strcpy(l1dirname, dir && *dir ? dir : ".");
dirname = l1dirname;
Strncpy(l1pattern, pat && *pat ? pat : "*", MAXPATL);
pattern = l1pattern;
browser = l1browser;
strcpy(fname, fn);
/* save current direcory info */
push_dir();
fl_set_object_label(l1title, prom);
fix_dir(dirname);
fl_deactivate_all_forms();
/* show default */
fl_set_input(l1dir, dirname);
fl_set_input(l1pat, pattern);
fl_set_input(l1title, fname);
load_browser(l1browser, dirname, pattern, fname);
bit_show_form(load1, FL_PLACE_HOTSPOT, bd, "FileSelector");
while ((ret = fl_do_forms()) != l1ok && ret != l1cancel)
if (ret == FL_EVENT)
(void) bit_qread(&val);
bit_hide_form(load1);
fl_activate_all_forms();
fnonly = fl_get_input(l1title);
if (ret != l1cancel && fnonly && *fnonly)
{
Strncpy(fname, fnonly, MAXFLEN);
Strncpy(combined, fl_get_input(l1dir), MAXDLEN);
pf = strncat(fix_dir(combined), fname, MAXCFL);
}
pop_dir();
return pf;
}
/******************************************************************
*
* Custom Form for write image to disk
*
****************************************************************{*/
#define DUMP_CB 2
#define MAXSHOWN 14 /* max formats per screen */
static IMG_IO *wio[30]; /* all formats capabale of writing */
static int totalwrite; /* total number of formats that write */
static int maxshown = MAXSHOWN; /* acutal shown */
static FL_FORM *dump;
static FL_OBJECT *dbrowser, *dok, *dcancel, *more, *ddir;
static FL_OBJECT *dpat, *dfname, *dopt, *d_f[MAXSHOWN];
static char d_pattern[MAXPATL + 1]; /* selection pattern */
static char d_dirname[MAXDLEN + 1]; /* current directory */
static void set_browser(FL_OBJECT *, const char *);
/*****************************************************************
* Gather all formats that can write and show them. we only need to
* do this once, because the no. of formats is a constant
****************************************************************/
static void
init_formats(void)
{
static int d_init;
int i;
register IMG_IO *ios = img_io + totalfmt, *io = img_io;
if (d_init)
return;
/* get all formats that is writable */
while (io < ios)
{
if (io->dump)
wio[totalwrite++] = io;
io++;
}
/* check if we have enuf button to show all formats */
if (maxshown >= totalwrite)
{ /* enuf button to show all formats */
fl_set_object_label(more, "All Formats");
more->active = 0; /* disable paging */
/* also hide un-used buttons */
for (i = totalwrite; i < maxshown; i++)
fl_hide_object(d_f[i]);
}
else
/* not enuf buttons */
{
fl_set_object_label(more, "More Formats");
more->active = 1; /* default. set it anyway */
}
d_init = 1;
}
/***********************************************************************
* Take care of the case where more image formats than that can be shown
* per screen.
*
**********************************************************************/
static int offset; /* offset into the wio structure */
static int wcurrent; /* selected format wio[current] */
static I_IO dumpinit; /* get writing options */
static I_wdef dumpdef; /* get options in string form */
static void
update_formats(void)
{
int i;
fl_freeze_form(dump);
for (i = 0; i < maxshown && i + offset < totalwrite; i++)
{
fl_show_object(d_f[i]);
fl_set_object_label(d_f[i], wio[i + offset]->key);
fl_set_button(d_f[i], (wcurrent == i + offset));
}
for (; i < maxshown; i++)
fl_hide_object_only(d_f[i]);
fl_unfreeze_form(dump);
}
/**********************************************************
* Paging
**********************************************************/
/*ARGSUSED*/
static void
wformat_cb(FL_OBJECT * ob, long q)
{
if (offset + maxshown <= totalwrite)
offset += maxshown;
else if (offset >= maxshown)
offset -= maxshown;
update_formats();
}
/**********************************************************
* Requested another format to write
*********************************************************/
/*ARGSUSED*/
static void
wformat_change(FL_OBJECT * ob, long q)
{
int id;
if (q + offset >= totalwrite)
return;
wcurrent = id = q + offset;
dumpinit = wio[id]->dumpi;
dumpdef = wio[id]->wdef;
fl_set_object_label(dopt, dumpdef ? dumpdef(imgptr) : "None");
change_extension(fname, wio[id]->ext);
fl_set_input(dfname, fname);
set_browser(dbrowser, fname);
(!dumpinit ? fl_deactivate_object : fl_activate_object) (dopt);
}
/******* utility routine for external use *******/
void
update_dumpinfo(const char *s)
{
fl_set_object_label(dopt, s);
}
/***************************************************************
* Search a browser for name and show it in the browser. If outside
* viewing area, shift it to view
****************************************************************/
static void
set_browser(FL_OBJECT * br, const char *name)
{
register int i, maxline, match = 0;
int topline;
maxline = fl_get_browser_maxline(br);
topline = fl_get_browser_topline(br);
fl_deselect_browser(br);
for (i = 1; !match && i <= maxline; i++)
match = Streq(fl_get_browser_line(br, i), name);
if (match)
{
fl_select_browser_line(br, --i);
/* if the current is off viewing area, move it */
if (i < topline)
i--;
else if (i > topline + 11)
i -= 8;
else
i = -1;
if (i > 0)
fl_set_browser_topline(br, i);
}
}
static void fn_cb(FL_OBJECT *, long);
static void dir_cb(FL_OBJECT *, long);
/*************************************************************
* Global entry point for writing images to disk
************************************************************/
int
do_dump(IPTR im)
{
int bd = 1, id, err, follow_load_dir = 1;
short val;
FL_OBJECT *ret;
create_the_forms();
if (!image_ready(im, "Write"))
return -1;
/* gather all formats capable of writing */
init_formats();
/* search currently requested format among the write-able formats */
for (id = 0; id < totalwrite && im->io->key != wio[id]->key; id++)
;
if (id == totalwrite)
{
/*
* the current loaded image format is not capable of write, choose
* one that is. only reasonable that the chosen one has the same
* type
*/
if (IS_CI(im))
{
for (id = 0; id < totalwrite && wio[id]->type != T_CMAP; id++)
;
}
else if (IS_CPACK(im))
{
for (id = 0; id < totalwrite && wio[id]->type != T_RGBA; id++)
;
}
/* if can't find match, get the first one */
im->io = wio[id %= totalwrite];
}
offset = (id / maxshown);
offset *= maxshown;
/* update reporting info and also initialization routine */
wcurrent = id;
update_formats();
/* see if there is writing options */
update_dumpinfo(im->io->wdef ? im->io->wdef(im) : "None");
/* functions to get writing options */
dumpinit = im->io->dumpi;
/* get default writing parameters in string representation */
dumpdef = im->io->wdef;
(dumpinit ? fl_activate_object : fl_deactivate_object) (dopt);
/* save current direcotry */
push_dir();
pattern = d_pattern;
dirname = d_dirname;
browser = dbrowser;
fl_set_input(dpat, pattern);
/* make it configuable some day */
follow_load_dir = 1;
if (follow_load_dir)
{
getcwd(dirname, sizeof(d_dirname) - 2);
}
else
{
chdir(dirname);
}
fix_dir(dirname);
fl_set_input(ddir, dirname);
strcpy(im->ofile, im->ifile);
strcpy(fname, im->ofile);
fl_set_input(dfname, fname);
load_browser(browser, dirname, pattern, fname);
set_browser(browser, fname);
deactivate_all_forms();
bit_show_form(dump, FL_PLACE_HOTSPOT, bd, "Write");
/*
* the following do while loop only terminates if cancel or succesful
* write. Bad write will not terminate the loop
*/
do
{
while ((ret = fl_do_forms()) != dok && ret != dcancel)
{
if (ret == FL_EVENT)
{
(void) bit_qread(&val);
}
else if (ret == dopt && dumpinit)
{
dumpinit(im);
update_dumpinfo(dumpdef ? dumpdef(im) : "None");
}
}
/* end of while loop: either cancel or write */
if (wcurrent < 0 || wcurrent >= totalwrite)
{
Bark("ImageWrite", "can't happen");
return -1;
}
id = wcurrent;
/*
* it is very important that there is no modification to the
* writing parameters after writing has started. Also any file IO,
* image loading activities must be suspended (re-entrant
* problems).
*/
err = 0;
if (ret == dok)
{
dir_cb(ddir, 0);
fn_cb(dfname, 0); /* check filename last time */
fl_deactivate_all_forms();
strcpy(im->ofile, fname);
set_current_window(dump->window);
err = write_image(wio[id], im, fname) < 0;
fl_activate_all_forms();
}
}
while (ret != dcancel && err);
fl_activate_all_forms();
pop_dir();
bit_hide_form(dump);
return 0;
}
/******************************************************************
* END OF writing routines
*****************************************************************}*/
/************************************************************
* Custom form for file loader
*
***********************************************************/
#define LOAD_CB 1
static FL_FORM *load;
static FL_OBJECT *lmbrowser;
static FL_OBJECT *ldir, *lpat, *ltotal, *loaded;
static char l_pattern[MAXPATL + 1];
static char l_dirname[MAXDLEN + 1];
static int totalf, loadedf;
/**************************************************************
* report current active file list length
************************************************************/
static void
show_loaded(void)
{
char p[20];
sprintf(p, "%4d Loaded", loadedf);
fl_set_object_label(loaded, p);
}
#if 0
static void
pre_check_cb(FL_OBJECT * ob, long q)
{
precheck = fl_get_button(ob);
}
#endif
/************************************************************
* load a mutitple-select browser. ff unused
***********************************************************/
static void
zap_all_events(void)
{
long dev;
short val;
while (fl_check_forms() || fl_qtest())
{
dev = fl_qread(&val);
bit_handle_event(dev, val);
}
}
/* ARGSUSED*/
static int
load_mbrowser(FL_OBJECT * br, const char *dir, const char *pat,
const char *ff)
{
int i, fnumb;
Dirlist *dirlist;
static int in_lm;
if (in_lm)
{
zap_all_events();
return -1;
}
in_lm = 1;
show_busy("ReadingDir ...");
if (!(dirlist = get_dir_list(dir, pat, &fnumb, rescan)))
{
Bark("LoadDir", dir);
end_busy();
in_lm = 0;
return -1;
}
sprintf(cmfn, "%4d total", totalf = fnumb);
fl_set_object_label(ltotal, cmfn);
loadedf = 0;
fl_freeze_form(br->form);
fl_clear_browser(br);
for (i = 0; dirlist[i].name; i++)
{
if (dirlist[i].type == FT_DIR)
{
sprintf(cmfn, "D %s", dirlist[i].name);
fl_add_browser_line(br, cmfn);
}
else if (dirlist[i].type == FT_FILE)
{
fl_add_browser_line(br, dirlist[i].name);
/* highlight if selected */
if (is_on_list(dir, dirlist[i].name))
{
loadedf++;
fl_select_browser_line(br, i + 1);
}
}
}
show_loaded();
fl_unfreeze_form(br->form);
end_busy();
in_lm = 0;
return fnumb;
}
/*******************************************************************
* Global entry to making file list
*****************************************************************/
void
load_files(void)
{
int bd = 1;
short val;
create_the_forms();
mload = 1;
dirname = l_dirname;
pattern = l_pattern;
browser = lmbrowser;
fix_dir(dirname);
fl_set_input(ldir, dirname);
fl_set_input(lpat, pattern);
load_mbrowser(browser, dirname, pattern, "");
deactivate_all_forms();
bit_show_form(load, FL_PLACE_HOTSPOT, bd, "Load");
while (bit_qread(&val) != KEYBD || val != 27)
;
fl_activate_all_forms();
bit_hide_form(load);
mload = 0;
return;
}
/********************************************************************
* common call back routines
****************************/
/********** filename call back ******************/
/* ARGSUSED */
static void
fn_cb(FL_OBJECT * obj, long arg)
{
const char *p;
p = fl_get_input(obj);
if (!p || !*p)
{
fl_set_input(obj, fname);
return;
}
strcpy(fname, p);
set_browser(browser, fname);
}
/************** directory name call back ****************/
static void
dir_cb(FL_OBJECT * obj, long arg)
{
const char *p;
char tmpdir[MAXDLEN + 2];
p = fl_get_input(obj);
if (!p || !*p)
{
fl_set_input(obj, dirname);
return;
}
if (Streq(p, dirname))
return;
/*
* this is necessary since static area in get_input is of a limited
* lenthg, last dirlen
*/
fix_dir(strcpy(tmpdir, p));
if (stat(tmpdir, &ffstat) || !(ffstat.st_mode & S_IFDIR))
{
Bark("LoadDir", tmpdir);
fl_set_input(obj, dirname);
return;
}
/* now, everying is ok, re-fill the browser */
strcpy(dirname, tmpdir);
chdir(dirname);
fl_set_input(obj, dirname);
/* load either multi-selection browser or single */
(arg == LOAD_CB ? load_mbrowser : load_browser)
(browser, dirname, pattern, fname);
}
/* pattern call back */
static void
pat_cb(FL_OBJECT * obj, long arg)
{
const char *p;
p = fl_get_input(obj);
if (!p)
{
fl_set_input(obj, dirname);
return;
}
if (Streq(p, pattern))
return;
Strncpy(pattern, p, MAXPATL);
if (arg == LOAD_CB)
{
load_mbrowser(browser, dirname, pattern, "");
}
else
{
load_browser(browser, dirname, pattern, fname);
}
}
/*************************************************************
* browser call back
************************************************************/
/* directory is marked by "D ". */
#define is_a_dir(t) (t[0] == 'D' && t[1] == ' ')
static void
browser_cb(FL_OBJECT * br, long arg)
{
char seltext[256];
char tmpdir[PATH_MAX];
strcpy(seltext, fl_get_browser_line(br, fl_get_browser(br)));
if (is_a_dir(seltext))
{
strcpy(seltext, seltext + 2);
strcat(strcpy(tmpdir, dirname), seltext);
fix_dir(tmpdir);
if (load_browser(br, tmpdir, pattern, fname) > 0)
{
strcpy(dirname, tmpdir);
fl_set_input(arg == FSELECT_CB ? l1dir : ddir, dirname);
}
}
else
{
fl_set_input(arg == FSELECT_CB ? l1title : dfname, seltext);
strcpy(fname, seltext);
}
}
/****************************************************************
* sometimes, the form does not work right in the multi-select
* mode. workaround: if reported clicks are very close, probably
* wrong
***************************************************************/
#include <sys/time.h>
#define SEP 600 /* milli sec */
static int
too_close(FL_OBJECT * br)
{
static int lastline;
int i, j;
j = ((i = fl_get_browser(br)) < 0) ? -i : i;
/* relevent only if selected same line */
if (j == lastline)
{
if (time_passed() < SEP)
{
if (i > 0)
fl_deselect_browser_line(br, i);
return 1;
}
}
reset_time();
lastline = j;
return 0;
}
/*******************************************************************
* multi-selection browser call back
*
* Here we must not double entry else if we hit a bad directory,
* recursion would occur.
*******************************************************************/
/* ARGSUSED */
static void
lbrowser_cb(FL_OBJECT * br, long NotUsed)
{
char seltext[256];
char tmpdir[PATH_MAX];
static int in_lbcb;
int which = fl_get_browser(br);
int i = (which > 0) ? which : -which;
if (too_close(br))
return;
if (in_lbcb)
{
zap_all_events();
return;
}
in_lbcb = 1;
strcpy(seltext, fl_get_browser_line(br, i));
if (is_a_dir(seltext))
{
strcpy(seltext, seltext + 2);
/* check before proceed as not to overwrite current dir if error */
strcat(strcpy(tmpdir, dirname), seltext);
fix_dir(tmpdir);
if (load_mbrowser(br, tmpdir, pattern, "") > 0)
{
strcpy(dirname, tmpdir);
fl_set_input(ldir, dirname);
}
}
else
{
if (which > 0)
{
if (!is_on_list(dirname, seltext))
{
add_to_list(dirname, seltext);
loadedf++;
}
}
else
{
if (is_on_list(dirname, seltext))
{
delete_from_list(dirname, seltext);
loadedf--;
}
}
}
show_loaded();
in_lbcb = 0;
}
/* ARGSUSED */
static void
re_scan_cb(FL_OBJECT * p, long q)
{
rescan = 1;
if (q == LOAD_CB)
{
load_mbrowser(browser, dirname, pattern, "");
}
else
{
load_browser(browser, dirname, pattern, fname);
}
rescan = 0;
}
/* ARGSUSED */
static void
load_all_cb(FL_OBJECT * p, long q)
{
int maxline = fl_get_browser_maxline(browser), i;
const char *sel;
loadedf = 0;
show_busy("");
fl_freeze_form(browser->form);
for (i = maxline; i >= 1; i--)
{
sel = fl_get_browser_line(browser, i);
if (!is_a_dir(sel))
{
if (!is_on_list(dirname, sel))
{
add_to_list(dirname, sel);
fl_select_browser_line(browser, i);
}
loadedf++;
}
}
show_loaded();
fl_unfreeze_form(browser->form);
end_busy();
}
/* ARGSUSED */
static void
unload_all_cb(FL_OBJECT * p, long q)
{
int maxline = fl_get_browser_maxline(browser), i;
const char *sel;
show_busy("");
fl_freeze_form(browser->form);
for (i = 1; i <= maxline; i++)
{
sel = fl_get_browser_line(browser, i);
if (!is_a_dir(sel) && is_on_list(dirname, sel))
{
delete_from_list(dirname, sel);
fl_deselect_browser_line(browser, i);
}
}
loadedf = 0;
show_loaded();
fl_unfreeze_form(browser->form);
end_busy();
}
static void
create_form_dump(void)
{
FL_OBJECT *obj;
int i;
float x, y, dx, dy;
dump = fl_bgn_form(FL_NO_BOX, 325.0, 365.0);
obj = fl_add_box(FL_UP_BOX, 0.0, 0.0, 325.0, 365.0, "");
fl_set_object_color(obj, 12, 47);
obj = fl_add_button(FL_HIDDEN_BUTTON, 0, 0, 325, 365, "");
fl_set_call_back(obj, help_cb, HELP_WRITE);
/* browser */
dbrowser = fl_add_browser(FL_HOLD_BROWSER, 10.0, 70.0, 160.0, 220.0, "");
fl_set_object_boxtype(dbrowser, FL_FRAME_BOX);
fl_set_object_color(dbrowser, 8, 50);
fl_set_call_back(dbrowser, browser_cb, DUMP_CB);
/* Finemame */
dfname = fl_add_input(FL_NI, 80.0, 40.0, 225.0, 20.0, "Filename:");
fl_set_object_boxtype(dfname, FL_SHADOW_BOX);
fl_set_object_color(dfname, 47, 51);
fl_set_call_back(dfname, fn_cb, DUMP_CB);
/* directory input */
ddir = fl_add_input(FL_NI, 75.0, 325.0, 235.0, 20.0, "Directory:");
fl_set_object_boxtype(ddir, FL_BORDER_BOX);
fl_set_object_color(ddir, 12, 51);
fl_set_object_lsize(ddir, 10.00);
fl_set_call_back(ddir, dir_cb, DUMP_CB);
/* pattern input */
dpat = fl_add_input(FL_NI, 75.0, 305.0, 235.0, 20.0, "Pattern:");
fl_set_object_boxtype(dpat, FL_BORDER_BOX);
fl_set_object_color(dpat, 12, 51);
fl_set_object_lsize(dpat, 10.0);
fl_set_call_back(dpat, pat_cb, DUMP_CB);
/* Options */
obj = fl_add_text(FL_NT, 10.0, 15.0, 70.0, 20.0, "Options:");
dopt = fl_add_button(FL_NORMAL_BUTTON, 80.0, 15.0, 225.0, 20.0, "");
fl_set_object_boxtype(dopt, FL_BORDER_BOX);
fl_set_object_lsize(dopt, 10.00);
/* format group */
fl_bgn_group();
dx = 70;
dy = 27;
for (i = 0, x = 175, y = 235; i < maxshown - 1 && y > 90; i += 2, y -= dy)
{
d_f[i] = obj = fl_add_roundbutton(FL_RB, x, y, 30, 30, "");
fl_set_object_lsize(obj, 10.00);
fl_set_object_lstyle(obj, FL_BOLD_STYLE);
fl_set_call_back(obj, wformat_change, i);
d_f[i + 1] = obj = fl_add_roundbutton(FL_RB, x + dx, y, 30, 30, "");
fl_set_object_lsize(obj, 10.0);
fl_set_object_lstyle(obj, FL_BOLD_STYLE);
fl_set_call_back(obj, wformat_change, i + 1);
}
maxshown = i;
more = fl_add_button(FL_NB, 185.0, 270.0, 115.0, 20.0, "");
fl_set_object_boxtype(more, FL_SHADOW_BOX);
fl_set_object_lcol(more, 4);
fl_set_object_lstyle(more, FL_ITALIC_STYLE);
fl_set_call_back(more, wformat_cb, 0);
fl_end_group();
/* Ok button */
dok = fl_add_button(FL_NORMAL_BUTTON, 245.0, 70.0, 65.0, 25.0, "OK");
fl_set_object_color(dok, 47, 2);
fl_set_object_lsize(dok, 10.0);
/* Cancel button */
dcancel = fl_add_button(FL_NB, 175.0, 70.0, 65.0, 25.0, "Cancel");
fl_set_object_color(dcancel, 47, 3);
fl_set_object_lsize(dcancel, 10.0);
fl_end_form();
fl_set_form_hotspot(dump, (245 + 32), (70 + 13));
}
static void
mload_done(FL_OBJECT * ob, long q)
{
fl_qenter(KEYBD, 27);
}
static void
create_form_load(void)
{
FL_OBJECT *obj;
load = fl_bgn_form(FL_NO_BOX, 285.0, 335.0);
obj = fl_add_box(FL_UP_BOX, 0.0, 0.0, 285.0, 335.0, "");
fl_set_object_color(obj, 9, 47);
fl_set_object_align(obj, FL_ALIGN_RIGHT);
obj = fl_add_button(FL_HIDDEN_BUTTON, 0, 0, 285, 335, "");
fl_set_call_back(obj, help_cb, HELP_LOAD);
/* directory input */
ldir = fl_add_input(FL_NI, 50.0, 285.0, 225.0, 20.0, "Dir:");
fl_set_object_boxtype(ldir, FL_BORDER_BOX);
fl_set_object_color(ldir, 47, 50);
fl_set_object_lsize(ldir, 10.00);
fl_set_call_back(ldir, dir_cb, LOAD_CB);
/* pattern input */
lpat = fl_add_input(FL_NI, 50.0, 265.0, 225.0, 20.0, "Pat:");
fl_set_object_boxtype(lpat, FL_BORDER_BOX);
fl_set_object_color(lpat, 47, 50);
fl_set_object_lsize(lpat, 10.00);
fl_set_call_back(lpat, pat_cb, LOAD_CB);
/* the brower */
lmbrowser = obj = fl_add_browser(FL_MBR, 10.0, 10.0, 145.0, 230.0, "");
fl_set_object_boxtype(obj, FL_SHADOW_BOX);
fl_set_object_color(obj, 50, 12);
fl_set_call_back(obj, lbrowser_cb, 0);
/* reporting */
ltotal = fl_add_text(FL_NORMAL_TEXT, 175.0, 210.0, 90.0, 20.0, "");
fl_set_object_boxtype(ltotal, FL_BORDER_BOX);
fl_set_object_lsize(ltotal, FL_SMALL_FONT);
fl_set_object_align(ltotal, FL_ALIGN_CENTER);
fl_set_object_lstyle(ltotal, FL_BOLD_STYLE);
loaded = fl_add_text(FL_NORMAL_TEXT, 175.0, 190.0, 90.0, 20.0, "");
fl_set_object_boxtype(loaded, FL_BORDER_BOX);
fl_set_object_lsize(loaded, FL_SMALL_FONT);
fl_set_object_align(loaded, FL_ALIGN_CENTER);
fl_set_object_lstyle(loaded, FL_BOLD_STYLE);
/* Control buttons */
obj = fl_add_button(FL_NB, 175.0, 10.0, 90.0, 25.0, "Ready");
fl_set_object_color(obj, FL_MAGIC1, FL_GREEN);
fl_set_object_lsize(obj, 10.0);
fl_set_call_back(obj, mload_done, 0);
fl_set_form_hotspot(load, 175.0 + 45.0, 23.0);
#if 0
obj = fl_add_button(FL_PB, 175.0, 150.0, 90.0, 25.0, "PreCheck");
fl_set_object_lsize(obj, 10.0);
fl_set_object_color(obj, FL_MAGIC1, FL_YELLOW);
fl_set_button(obj, precheck);
fl_set_call_back(obj, pre_check_cb, 0);
#endif
obj = fl_add_button(FL_NB, 175.0, 125.0, 90.0, 25.0, "Load All");
fl_set_object_color(obj, FL_MAGIC1, FL_YELLOW);
fl_set_call_back(obj, load_all_cb, 0);
fl_set_object_lsize(obj, 10.0);
obj = fl_add_button(FL_NB, 175.0, 100.0, 90.0, 25.0, "Unload all");
fl_set_object_color(obj, FL_MAGIC1, FL_YELLOW);
fl_set_call_back(obj, unload_all_cb, 0);
fl_set_object_lsize(obj, 10.0);
obj = fl_add_button(FL_NB, 175.0, 75.0, 90.0, 25.0, "Re-scan");
fl_set_object_color(obj, FL_MAGIC1, FL_BLUE);
fl_set_call_back(obj, re_scan_cb, LOAD_CB);
fl_set_object_lsize(obj, 10.0);
fl_end_form();
}
static void
create_form_load1(void)
{
FL_OBJECT *obj;
load1 = fl_bgn_form(FL_NO_BOX, 290.0, 330.0);
obj = fl_add_box(FL_UP_BOX, 0.0, 0.0, 290.0, 330.0, "");
/* directory */
l1dir = fl_add_input(FL_NORMAL_INPUT, 50.0, 295.0, 225.0, 20.0, "Dir:");
fl_set_object_boxtype(l1dir, FL_BORDER_BOX);
fl_set_object_color(l1dir, 47, 50);
fl_set_object_lsize(l1dir, 10.000000);
fl_set_call_back(l1dir, dir_cb, FSELECT_CB);
/* the browser */
l1browser = fl_add_browser(FL_HOLD_BROWSER, 10.0, 70.0, 140.0, 190.0, "");
fl_set_object_boxtype(l1browser, FL_SHADOW_BOX);
fl_set_object_color(l1browser, 50, 12);
fl_set_call_back(l1browser, browser_cb, FSELECT_CB);
/* pattern */
l1pat = fl_add_input(FL_NORMAL_INPUT, 50.0, 275.0, 225.0, 20.0, "Pat:");
fl_set_object_boxtype(l1pat, FL_BORDER_BOX);
fl_set_object_color(l1pat, 47, 50);
fl_set_object_lsize(l1pat, 10.00);
fl_set_call_back(l1pat, pat_cb, FSELECT_CB);
/* file input */
l1title = fl_add_input(FL_NORMAL_INPUT, 30.0, 15.0, 225.0, 25.0, "");
fl_set_object_boxtype(l1title, FL_SHADOW_BOX);
fl_set_object_color(l1title, 47, 51);
fl_set_object_lcol(l1title, FL_BLUE);
fl_set_object_lsize(l1title, 10.000000);
fl_set_object_align(l1title, FL_ALIGN_TOP);
/* controls */
l1ok = fl_add_button(FL_NB, 175.0, 75.0, 90.0, 25.0, "Ready");
fl_set_object_color(l1ok, 47, 2);
fl_set_object_lsize(l1ok, 10.000000);
l1cancel = fl_add_button(FL_NB, 175.0, 110.0, 90.0, 25.0, "Cancel");
fl_set_object_color(l1cancel, 47, 3);
fl_set_object_lsize(l1cancel, 10.000000);
obj = fl_add_button(FL_NB, 175.0, 230.0, 90.0, 25.0, "Re-scan");
fl_set_object_lsize(obj, 10.000000);
fl_set_call_back(obj, re_scan_cb, FSELECT_CB);
fl_end_form();
fl_set_form_hotspot(load1, (175 + 45), (75 + 12));
}
static void
create_the_forms(void)
{
static int form_ok;
if (form_ok)
return;
create_form_dump();
create_form_load();
create_form_load1();
strcpy(d_dirname, startdir);
strcpy(l_dirname, ".");
strcpy(d_pattern, "*");
strcpy(l_pattern, "*");
form_ok = 1;
}